//
//  DeviceInfoViewCell.swift
//  ams
//
//  Created by yangyuan on 2017/6/27.
//  Copyright © 2017年 coterjiesen. All rights reserved.
//

import UIKit

class DeviceInfoview: UIView{
    let lableSNTile : UILabel = {
        let lable = UILabel()
        lable.font = v2Font(15)
        lable.text = "SN:"
        return lable
    }()
    
    let lableSNValue : UILabel = {
        let lable = UILabel()
        lable.font = v2Font(14)
        lable.text = "sn23435345dsf788788"
        return lable
    }()
    
    let lableStatusTitle : UILabel = {
        let lable = UILabel()
        lable.font = v2Font(16)
        lable.text = "状态"
        return lable
    }()
    
    let lableStatusValue : UILabel = {
        let lable = UILabel()
        lable.font = v2Font(13)
        lable.text = "可用"
        return lable
    }()
    
    let lableTimeTile : UILabel = {
        let lable = UILabel()
        lable.font = v2Font(15)
        lable.text = "操作时间:"
        return lable
    }()
    
    let lableTimeValue : UILabel = {
        let lable = UILabel()
        lable.font = v2Font(14)
        lable.text = "2017/03/15 11:12:13"
        return lable
    }()
    let leftView = UIView()
    let horizontalLine = UILabel()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        leftView.backgroundColor = CuColor.colors.v2_ButtonBackgroundColor
        horizontalLine.backgroundColor = CuColor.colors.v2_ButtonBackgroundColor
        self.addSubview(leftView)
        self.addSubview(lableSNTile)
        self.addSubview(lableSNValue)
        self.addSubview(lableTimeTile)
        self.addSubview(lableTimeValue)
        self.addSubview(horizontalLine)
        leftView.addSubview(lableStatusTitle)
        leftView.addSubview(lableStatusValue)
        setupLayout()
    }
    func setupLayout(){
        self.snp.makeConstraints { (make) in
            make.top.left.right.bottom.equalTo(self)
        }
        leftView.snp.makeConstraints { (make) in
            make.left.top.bottom.equalTo(self)
            make.width.equalTo(SCREEN_WIDTH / 5)
        }
        lableStatusTitle.snp.makeConstraints { (make) in
            make.centerX.equalTo(leftView)
            make.centerY.equalTo(self).offset(-12)
        }
        lableStatusValue.snp.makeConstraints { (make) in
            make.centerX.equalTo(leftView)
            make.centerY.equalTo(self).offset(12)
        }
        horizontalLine.snp.makeConstraints { (make) in
            make.left.equalTo(leftView.snp.right).offset(6)
            make.right.equalTo(-6)
            make.centerY.equalTo(self)
            make.height.equalTo(2)
        }
        lableSNTile.snp.makeConstraints { (make) in
            make.left.equalTo(horizontalLine)
            make.centerY.equalTo(self).offset(-12)
        }
        lableSNValue.snp.makeConstraints { (make) in
            make.left.equalTo(lableSNTile.snp.right).offset(6)
            make.top.equalTo(lableSNTile)
        }
        lableTimeTile.snp.makeConstraints { (make) in
            make.left.equalTo(horizontalLine)
            make.centerY.equalTo(self).offset(12)
        }
        lableTimeValue.snp.makeConstraints { (make) in
            make.left.equalTo(lableTimeTile.snp.right).offset(6)
            make.top.equalTo(lableTimeTile)
        }
    }
}

class DeviceInfoViewCell: UITableViewCell{
    
    var content = DeviceInfoview()
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    required override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    func setupUI(){
        self.isUserInteractionEnabled = false
        self.backgroundColor = UIColor.clear
        self.selectedBackgroundView?.backgroundColor = UIColor.clear
        self.selectionStyle = .none
        self.layer.cornerRadius = 20
        self.contentView.addSubview(content)
        content.snp.makeConstraints { (make) in
            make.top.equalTo(self.contentView).offset(2)
            make.left.right.bottom.equalTo(self.contentView)
        }
    }
    func bind(data : deviceInfo){
        self.content.lableSNValue.text = data.SN
        self.content.lableTimeValue.text = data.opTime
        self.content.lableStatusValue.text = deviceStatus[data.status]
    }
    
}
